#!/usr/bin/env python
import sys
import os
import uprgae

os.system("clear")
uprgae.printheader()
print 
print "** Accounts Activation Report **"
print "Login first to your domain"
uprgae.login()

print
print "Gathering activation data from " + uprgae.domain
print

pagina=uprgae._service.RetrievePageOfUsers(start_username=None)
startusername=None

numusuarios=0
activaciones=0
page=1

file=open("activaciones.gae",'w')

while pagina!=None:
	print "========== Pagina ",page, "=========="
	print
	for userentry in pagina.entry:
		if userentry.login.agreed_to_terms=="true":
			print userentry.name.given_name,userentry.name.family_name
			file.write(userentry.name.given_name + " " + userentry.name.family_name + "\n")		
			activaciones=activaciones+1
		numusuarios=numusuarios + 1
	if startusername != userentry.login.user_name:
		startusername=userentry.login.user_name
		pagina=uprgae._service.RetrievePageOfUsers(start_username=startusername)
		page=page + 1
		print
	else:
		pagina=None
	
file.close()
print
print "List of activated users was saved in file 'activaciones.gae'"
print "Found ",activaciones, " users that have activated their account"
print "from a total of ",numusuarios, " accounts or a %3.0f %% of the population." % (float(activaciones)/numusuarios*100)
print





